<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />

<!-- Optional theme -->
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css" />

<!-- Latest compiled and minified JavaScript -->
<script
	src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

<title>ES config</title>
</head>
<body>
	<form:form method="POST" commandName="es"
		action="${pageContext.request.contextPath}/es/rules">
		<input type="hidden" id="esId" name="esId" value="${esId}"/>
		<input type="hidden" id="layersId" name="layersId" value="${layersId}"/>
		<input type="hidden" id="blocksId" name="blocksId" value="${blocksId}"/>
		<c:forEach var="block" items="${es.blocks}" varStatus="b">
			<br />
				Fill rule base for block: ${block.name}
				<br />
			<table style="text-align: center;" border="1px" cellpadding="0"
				cellspacing="0">
				<thead>
					<tr>
					<th>Nam.</th>
						<c:forEach var="input" items="${block.inputs}" varStatus="i">
							<th>${input}</th>
						</c:forEach>
						<th>${block.output }</th>
					</tr>
				</thead>
				<tbody>
					<c:set var="index" value="${1 }" scope="page"/>
					<c:forEach begin="0" end="${block.countOfInputs - 1}">
						<c:set var="index" value="${index * 5 }" scope="page"/>
					</c:forEach>
					<c:forEach begin="0" end="${index - 1}" varStatus="r">
						<tr>
						<td>${r.index + 1}</td>
							<c:set var="inputIndex" value="${0}" scope="page"/>
							<c:forEach var="input" items="${block.inputs}" varStatus="in">
								<td>
									<form:select path="blocks[${b.index }].rules[${r.index }][${inputIndex }]">
											<form:options items="${terms}" />
									</form:select>
								</td>
								<c:set var="inputIndex" value="${inputIndex + 1 }" scope="page"/>
							</c:forEach>
							<td>
								<form:select path="blocks[${b.index }].rules[${r.index }][${inputIndex}]">
										<form:options items="${terms }" />
								</form:select>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</c:forEach>
		<br />
		<input type="submit" value="Save" class="btn btn-default" />
	</form:form>
</body>
</html>